def merge_sort(a):
    if len(a)<=1:
        return a
    num=len(a)//2
    left=merge_sort(a[:num])
    right=merge_sort(a[num:])
    return merge(left,right)
 
def merge(left,right):
    l,r=0,0
    result=[]
    while l<len(left) and r<len(right):
        if left[l]<right[r]:
            result.append(left[l])
            l+=1
        else:
            result.append(right[r])
            r+=1
    result+=left[l:]
    result+=right[r:]
    return result
 
a=[8,4,5,7,1,3,6,2]
ans=merge_sort(a)
print(ans)